package com.twohand.admin.Service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.twohand.admin.Dto.SwipeListQueryDto;
import com.twohand.admin.Entity.Swipe;
import com.twohand.admin.Mapper.SwipeMapper;
import com.twohand.admin.Service.SwipeService;
import com.twohand.admin.Util.PageResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SwipeServiceImpl implements SwipeService {
    @Autowired
    SwipeMapper swipeMapper;
    @Override
    public PageResponse<Swipe> getAllSwipe(SwipeListQueryDto swipeListQueryDto) {
        PageHelper.startPage(swipeListQueryDto.getPageNum(),swipeListQueryDto.getPageSize());
        List <Swipe> swipeList = swipeMapper.selectList(null);
        PageInfo<Swipe> swipePageInfo = new PageInfo<>(swipeList);
        return new PageResponse<Swipe>(swipePageInfo,swipeList);
    }

    @Override
    public Boolean addSwipe(Swipe swipe) {
        return swipeMapper.insert(swipe) > 0;
    }

    @Override
    public Boolean updateSwipe(Swipe swipe) {
        return swipeMapper.updateById(swipe) > 0;
    }

    @Override
    public Boolean delSwipe(Integer id) {
        return swipeMapper.deleteById(id) > 0;
    }
}
